package org.september.pisces.menuframe.service;

import java.util.Map;

import org.september.core.component.ApplicationContextHolder;
import org.september.pisces.module.api.PiscesModule;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

@Service
public class LoadModuleService implements ApplicationListener<ContextRefreshedEvent> {

	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		if (event.getApplicationContext().getParent() == null) {
			// 父容器为空，说明到达根容器，bean加载完成
			System.out.println("所有的bean都加载完成了");
			Map<String, PiscesModule> modules = ApplicationContextHolder.getContext().getBeansOfType(PiscesModule.class);
			for (PiscesModule pm : modules.values()) {
				pm.init();
			}
		}
	}

}
